package exercises.leetcode;

import java.util.ArrayList;

/**
 * <a href="">
 * </a>
 *
 * <p><span color="#87CEEB">描述:</span>
 *
 * @author or2
 * @date 2021年10月28日 时间: 19:49
 */
public class No500 {
    public String[] findWords(String[] words) {
        byte[] aux = new byte[26];
        char[] fi = {'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'};
        for (char c : fi) aux[c - 'a'] = 1;
        char[] se = {'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'};
        for (char c : se) aux[c - 'a'] = 2;
        char[] th = {'z', 'x', 'c', 'v', 'b', 'n', 'm'};
        for (char c : th) aux[c - 'a'] = 4;

        var res = new ArrayList<String>();
        for (String word : words) {
            int bit = 0;
            for (int i = 0, len = word.length(); i < len; i++) bit |= aux[Character.toLowerCase(word.charAt(i)) - 'a'];
            if (bit < 3 || bit == 4) res.add(word);
        }

        return res.toArray(String[]::new);
    }
}
